using System;
using System.Collections.Generic;
using System.Threading;

namespace XamlTest
{
   public class TestSynchronizationContext : SynchronizationContext
   {
      private readonly List<Tuple<SendOrPostCallback, object>> pending = new List<Tuple<SendOrPostCallback, object>>();

      public override void Send(SendOrPostCallback d, object state)
      {
         d(state);
      }

      public override void Post(SendOrPostCallback d, object state)
      {
         pending.Add(Tuple.Create(d, state));
      }

      public void DeliverPosted()
      {
         pending.ForEach(x => x.Item1(x.Item2));
      }
   }
}